//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    internal class TableCell : IOfficeXmlSerializable
    {
        internal const string xmlName = "tc";
        private OfficeArtExtensionList extLst;
        private int gridSpan = 1;
        private bool hMerge;
        private int rowSpan = 1;
        private TableCellProperties tcPr;
        private TextBody txBody;
        private bool vMerge;

        #region IOfficeXmlSerializable Members

        /// <summary>
        /// Generates an object from its XML representation
        /// </summary>
        /// <param name="context"></param>
        public void ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read(xmlName))
            {
                rowSpan = c.GetOptionalInteger("rowSpan", 1);
                gridSpan = c.GetOptionalInteger("gridSpan", 1);
                hMerge = c.GetOptionalBoolean("hMerge", false);
                vMerge = c.GetOptionalBoolean("vMerge", false);
                txBody = c.ReadOptionalElementAs<TextBody>("txBody");
                tcPr = c.ReadOptionalElement<TableCellProperties>(TableCellProperties.xmlName);
                extLst = c.ReadOptionalElement<OfficeArtExtensionList>("extLst");
            }
        }

        /// <summary>
        /// Convert an object into its XML representation
        /// </summary>
        /// <param name="context"></param>
        public void WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write(xmlName))
            {
                c.SetOptionalInteger("rowSpan", rowSpan, 1);
                c.SetOptionalInteger("gridSpan", gridSpan, 1);
                c.SetOptionalBoolean("hMerge", hMerge, false);
                c.SetOptionalBoolean("vMerge", vMerge, false);
                c.WriteOptionalElementAs(txBody, "txBody");
                c.WriteOptionalElement(tcPr);
                c.WriteOptionalElement(extLst);
            }
        }

        #endregion
    }
}